<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>权限列表</title>
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="/manager/easyui/themes/icon.css">
    <script type="text/javascript" src="/manager/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/manager/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript">
        //工具栏
        var toolbar = [{
            text: '修改',
            iconCls: 'icon-edit',
            handler: function () {
                $('#dd').dialog('open');
                let row = $("#userlist").datagrid("getSelected");
                $("#update-id").textbox("setValue", row.id);
                $("#update-url").textbox("setValue", row.url);
                $("#update-name").textbox("setValue", row.name);
                $("#update-sname").textbox("setValue", row.sname);
                $("#update-parentid").combobox("clear");
                $("#update-parentid").combobox("select", row.parentid);
            }
        }];
        $(function () {
            $('#userlist').datagrid({
                title: '权限列表',
                iconCls: 'icon-save',
                url: '/manager/permission/findAllPermission',
                columns: [
                    [
                        {field: 'id', title: '权限ID', width: 100, align: 'center'},
                        {field: 'name', title: '权限名称', width: 100, align: 'center'},
                        {field: 'url', title: '权限URL', width: 100, align: 'center'},
                        {
                            field: 'module', title: '权限所在模块', width: 80, align: 'center',
                            formatter: function (value, row, index) {
                                return value !=null ? value.name : null;
                            }
                        },
                        {field: 'sname', title: '权限操作名称', width: 200, align: 'center'}
                    ]],
                pagination: true,
                singleSelect:true,//是否开启单选
                toolbar: toolbar
            });
            //初始化查询栏
            $("#submit_search").linkbutton({iconCls: 'icon-search', plain: true})
                .click(function () {
                    let data = {};
                    let moduleName = $("#search-module-name").val();
                    let permissionName = $("#search-permission-name").val();
                    if (moduleName != "") {
                        data.moduleName = moduleName;
                    }
                    if (permissionName != "") {
                        data.permissionName = permissionName;
                    }
                    $('#userlist').datagrid("reload", data);
                });

            //初始化修改窗口
            $('#dd').dialog({
                title: '修改权限',
                width: 700,
                height: 500,
                closed: true,
                cache: false,
                href: '',
                modal: true,
                iconCls: 'icon-save',
                buttons: [{
                    text: '提交',
                    iconCls: 'icon-ok',
                    handler: function () {
                        $.post("/manager/permission/update", $("#ff").serialize(), rs => {
                            if (rs.status == 200) {
                                $('#userlist').datagrid("reload");
                            } else {
                                alert(rs.msg);
                            }
                        });
                    }
                }, {
                    text: '关闭',
                    handler: function () {
                        $('#dd').dialog("close");
                    }
                }]
            });

            // 下拉显示所有
            $.post("/manager/permission/findAllModules", rs => {
                $("#update-parentid").combobox({
                    data:rs.data,
                    // width:200,//宽度
                    // value:"请选择",//默认值
                    valueField:"id",//指定数据中那个属性是option的value
                    textField:"name",//指定数据中那个属性是option的text
                    singleSelect:true,//是否开启单选
                });
            });
        });
    </script>
</head>
<body>
<form name="searchform" method="post" action="" id="searchform">
    <td width="70" height="30"><strong>权限查询：</strong></td>
    <td height="30">
        <input type="text" name="keyword" id="search-module-name" size=20 placeholder="模块名称"/>
        <input type="text" name="keyword" id="search-permission-name" size=20 placeholder="权限名称"/>
        <a id="submit_search">搜索</a>
    </td>
</form>
<table id="userlist"></table>
<div id="dd">
    <div align="center" style="margin-top: 30px">
        <form id="ff" method="post">
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="update-id" name="id" style="width:50%" data-options="label:'权限ID:'"
                       readonly="readonly"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="update-url" name="url" style="width:50%" data-options="label:'权限url:'"
                       readonly="readonly"/>
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="update-name" name="name" style="width:50%"
                       data-options="label:'权限名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <input class="easyui-textbox" id="update-sname" name="sname" style="width:50%"
                       data-options="label:'操作名称:',required:true">
            </div>
            <div style="margin-bottom:20px">
                <select class="easyui-combobox" id="update-parentid" name="parentid" label="所属模块:" style="width:50%"
                        data-options="multiple:true">
                    <option value="-1">请选择模块</option>
                    <option value="be_name">用户管理</option>
                    <option value="be_intro">权限管理</option>
                    <option value="be_intro">元数据管理</option>
                </select>
            </div>
        </form>
    </div>
</div>
</body>
</html>